#include "utils.h"
#include <ctime>
#include <cstdlib>
#include <cstdio>

using namespace std;

#define RAND_MAX_VAL 4294967295
#define RAND_MIN_VAL 268435456

unsigned int Utils::StringHashCode(const char *src)
{
    unsigned int seed = 1313;
    unsigned int hash = 0;
    while (*src)
    {
        hash = (*src++) + seed * hash;
    }
    return (hash & 0x7FFFFFFF);
}

string Utils::GenRandToken()
{
    unsigned int seed = time(0);
    srand(seed);

    int num = rand() % (RAND_MAX_VAL - RAND_MIN_VAL + 1) + RAND_MIN_VAL;
    char hex[9] = {0};
    sprintf(hex, "%x", num);
    string ret(hex);
    return ret;
}